package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.vo.CommentInfoVo;
import com.atguigu.eduservice.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author AIR
 * @since 2022-10-11
 */
@RestController
@RequestMapping("/eduservice/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    //根据课程id 分页查询课程评论方法
    @GetMapping("getPageComment/{current}/{limit}/{courseId}")
    public R getPageComment(
            @PathVariable Long current,
            @PathVariable Long limit,
            @PathVariable String courseId
            ){
        Map<String,Object> map = commentService.getCommentByCourseId(current,limit,courseId);
        return R.ok().data(map);
    }

    //添加评论内容，课程id和讲师id，通过前端token获取 -> （用户id，用户昵称，用户图像）
    @PostMapping("saveComment")
    public R saveComment(@RequestBody CommentInfoVo commentInfoVo, HttpServletRequest request){
       commentService.insertComment(commentInfoVo,request);
       return R.ok();
    }

}
